package com.ruoyi.system.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.google.common.collect.ImmutableList;
import com.ruoyi.common.core.domain.entity.SysEquipment;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.system.mapper.SysEquipmentMapper;
import com.ruoyi.system.service.ISysEquipmentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.SQLIntegrityConstraintViolationException;
import java.util.List;

@Service
public class SysEquipmenetServiceImpl implements ISysEquipmentService {

    @Resource
    private SysEquipmentMapper equipmentMapper;


    @Override
    public int addNewEquipment(SysEquipment s) {
        try {
            equipmentMapper.deleteByNameAndDelFlag(s.getEquipmentName());
            return equipmentMapper.addNewEquipment(s);
        } catch (Exception e) {
            if (e.getMessage().contains("Duplicate")) {
                throw new ServiceException(s.getEquipmentName() + "已存在");
            }
            return 0;
        }
    }

    @Override
    public int deleteEquipmentMultiByIds(List<Long> ids) {
        return equipmentMapper.deleteEquipmentMultiByIds(ids);
    }

    @Override
    public int updateEquipment(SysEquipment s) {
        return equipmentMapper.updateEquipment(s);
    }

    @Override
    public List<SysEquipment> records(SysEquipment s) {
        return equipmentMapper.records(s);
    }
}
